from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
import pytest
from httprunner import Parameters

class TestCaseUsergroup(HttpRunner):
    @pytest.mark.parametrize(
        'param',
        Parameters({"account":["admin"],"pwd":["920509"]}),)
    def test_start(self, param):
        super().test_start(param)
    config = Config("测试")\
        .base_url("http://60.205.190.66:8899")\
        .verify(False)\
        # .variables(**{"user": "admin", "pwd": "${get_pwd()}"})

    teststeps = [
        Step(RunRequest("登录")
             .post("/adminapi/login")
             .with_headers(
            **{'Host': '60.205.190.66:8899',
               'Content-Length': '48', 'Accept': 'application/json, text/plain, */*',
               'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36',
               'Content-Type': 'application/json;charset=UTF-8',
               'Origin': 'http://60.205.190.66:8899',
               'Referer': 'http://60.205.190.66:8899/admin/login',
               'Accept-Encoding': 'gzip, deflate',
               'Accept-Language': 'zh-CN,zh;q=0.9',
               'Cookie': 'WS_ADMIN_URL=ws://60.205.190.66:8899/notice; WS_CHAT_URL=ws://60.205.190.66:8899/msg; think_lang=zh-cn; PHPSESSID=7b831f72e9da15fb8f86a361ca7fcdce; collapsed=false',
               'Connection': 'keep-alive'})
             .with_cookies(
            **{'WS_ADMIN_URL': 'ws://60.205.190.66:8899/notice',
               'WS_CHAT_URL': 'ws://60.205.190.66:8899/msg',
               'think_lang': 'zh-cn',
               'PHPSESSID': '7b831f72e9da15fb8f86a361ca7fcdce',
               'collapsed': 'false'})
             .with_json({'account': '${account}', 'pwd': '${pwd}', 'imgcode': 'a'})
             .extract()
             .with_jmespath("body.data.token", "token")
             .with_jmespath('headers.Server','cookies')
             .validate()
             .assert_equal("status_code", 200)
             .assert_equal('headers."Content-Type"', "application/json; charset=utf-8")
             .assert_equal("body.status", 200)
             .assert_equal("body.msg", "ok")),
    ]


if __name__ == "__main__":
    TestCaseUsergroup().test_start()